
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<div class="modal" id="batchImportDiv" tabindex="-1" role="dialog" aria-hidden="true" style="width: auto;">

	<div class="modal-dialog modal-lg" role="document">

		<div class="modal-content animated bounceInRight">

			<div class="modal-header">
				<h4 class="modal-title">物料/服务批量导入</h4>
				<button type="button" class="close" data-dismiss="modal"
					aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
			</div>

			<div class="modal-body" style="padding-bottom: 20px; padding-top: 5px;">
				<form id="form">
					<input type="file" name="Excelfile" id="Excelfile"/>
					<input type="submit" value="开始上传"/>
				</form>
				<a href="dowload/物资批量导入模板.xlsx">下载模板</a>
			</div>

		</div>

	</div>

</div>

<script type="text/javascript" language="javascript">
	$(form).on("change","#Excelfile",function(e){
	    if(!CheckExcel()){
            return false;
		}
	}).submit(function(){
	    if(CheckExcel()){
	        debugger
            var formData = new FormData();
            formData.append("courseFile",$("#Excelfile")[0].files[0]);
            $.ajax({
                url:'web/mdMaterial/upload/material', /*接口域名地址*/
                type:'post',
                data: formData,
                contentType: false,
                processData: false,
                async:true,
                dataType: "html",
                success:function(data){
                    console.log(data);
                    var json = JSON.parse(data);

                    if(json.result=="success"){
                        alert(json.message);
                        $('#batchImportDiv').modal('hide');
                        window.location.reload()
                    }else{
                        alert(json.message);
                        $('#batchImportDiv').modal('hide');
                        window.location.reload()

                    }
                }
            });
            return false;
		}else{
            return false;
		}
	});
	function CheckExcel() {
        debugger
		var mime = document.getElementById('Excelfile').value;
		if(mime == ""){
            alert("请选择上传的文件!");
            return false;
		}
		mime = mime.toLowerCase().substr(mime.lastIndexOf("."));

		if (!(mime == ".xls" || mime == ".xlsx")) {
			alert("请导入正确的EXCEL文件，仅支持xls格式!");
			return false;
		}else{
            return true;
		}
	}
</script>
